<template>
  <div>
    <div class="demo-nav">
      <i class="van-icon van-icon-arrow-left van-nav-bar__arrow" style="left: -115px;font-size: 20px" @click="goBack"></i>
      <div class="demo-nav__title" style="margin-left: -10px">{{form.title}}</div>
    </div>
    <div>
      <van-form @submit="onSubmit">
        <van-field
            v-model="form.detail"
            rows="2"
            autosize
            label="留言内容"
            type="textarea"
            maxlength="50"
            placeholder="留言内容"
            show-word-limit
            input-align="right"
        />
        <van-field
            v-model="form.reply"
            rows="2"
            autosize
            label="回复"
            type="textarea"
            maxlength="50"
            placeholder="回复"
            show-word-limit
            input-align="right"
        />
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit" v-if="isReply">提交</van-button>
          <van-button round block type="info" native-type="button" @click="$router.go(-1)" v-else>返回</van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>
<style>
.demo-nav {
  position: relative;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  height: 56px;
  background-color: #fff;
}
.demo-nav__title {
  font-weight: 600;
  font-size: 17px;
  text-transform: capitalize;
}
</style>
<script>
import axios from "axios";

export default {
  data() {
    return {
      user:this.$store.state.userinfo.user.user,
      nameTmp:'',
      isReply:false,
      form:{
        mid:'',
        title:'',
        reply:'',
        detail:'',
        namefrom:'',
        nameto:'',
        fromavatar:'',
      }
    }
  },
  created() {
    var _this = this;
    _this.form.mid = _this.$route.query.id
    _this.form.title = _this.$route.query.title
    _this.form.detail = _this.$route.query.detail
    _this.form.namefrom = _this.$route.query.namefrom
    _this.form.nameto = _this.$route.query.nameto
    _this.form.date = _this.$route.query.date
    _this.axios({
      method:'get',
      url:'message/reflexByMid/'+_this.form.mid,
    }).then(function (rep){
      _this.form.reply = rep.data.data.reflex.detail
      if(_this.form.reply==""){
        _this.isReply=true
      }
    })
  },
  methods: {
    goBack(){
      this.$router.go(-1);
    },
    onSubmit() {
      var _this = this
      _this.form.detail = _this.form.reply
      _this.nameTmp = _this.form.namefrom
      _this.form.namefrom = _this.form.nameto
      _this.form.nameto = _this.nameTmp
      _this.axios({
        method:'post',
        url:'/message/AddReply',
        data:_this.form,
      }).then(function (rep){
        alert("成功!")
        _this.$router.push("message");
      })
    },
  }
}
</script>

<style scoped>

</style>